package com.divemotor.ventarepuestosinternet.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.divemotor.ventarepuestosinternet.beans.adapter.DataAdapter;
import com.divemotor.ventarepuestosinternet.dao.MonedaDAO;
import com.divemotor.ventarepuestosinternet.model.Moneda;

@SuppressWarnings("unchecked")
@Repository(value = "monedaDAO")
public class MonedaDAOImpl implements MonedaDAO, Serializable {

	private static final long serialVersionUID = -3421871158677619039L;
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public List<DataAdapter> listarMonedaAdapter(){
		return getSessionFactory().getCurrentSession().getNamedQuery("Moneda.buscarAdapter").list();
	}

	@Override
	public List<Moneda> listar() {
		return getSessionFactory().getCurrentSession().createQuery("from Moneda m order by m.nombre").list();
	}

	@Override
	public Moneda obtenerPorId(Moneda moneda) {		
		return (Moneda) getSessionFactory().getCurrentSession().createQuery("from Moneda where idMoneda = :monedaId")
						.setParameter("monedaId", moneda.getIdMoneda()).uniqueResult();
	}

}
